package main

import (
	"fmt"
	"strconv"
)

//启动一个子goroutine,向带缓存的通道中写出数据
//另一个子goroutine从该通道中读取数据
var done chan bool
func main() {
	done=make(chan bool)
	ch1 := make(chan string, 4)
	go sendData1(ch1)
	go readData1(ch1)
	<-done
	fmt.Println("main over")
}

func sendData1(ch1 chan string) {
	for i := 0; i < 10; i++ {
		ch1 <- "数据" + strconv.Itoa(i)
		fmt.Println("写出数据：", i)
	}
	close(ch1)
}
func readData1(ch1 chan string) {
	for {
		v, ok := <-ch1
		if !ok {
			fmt.Println("数据读完了.", ok)
			done<-true
			break
		}
		fmt.Println(v, ok)
	}
}
